import { Method } from "axios";
import systemStore  from "../store/SystemStore";

export default class utils{
    /**修饰数据(get时，返回 axiosConfig,否则返回 data) */
    static decorateData = (_data: any, url: string, method: Method = "post"): any => {

      // console.log('请求路径', url);

      // let requestConfig: AxiosRequestConfig = {};
      // requestConfig.headers = {
      //     'Access-Control-Allow-Origin': '*',
      //     "Content-Type": "application/x-www-form-urlencoded",
      //     //   "Access-Control-Allow-Credentials":true
      // };
      _data = _data || { }
      if( method == 'get'){
          //_data["access_token"] = systemStore.access_token;
          let config = {
              headers: {
                  ...(_data.headers || {}),
                  access_token:systemStore.access_token
              },
              params:_data
          }
          return config;
      }else{
          _data["access_token"] = systemStore.access_token;
          _data = systemStore.createOpenApiSecret(_data);
      }
      
      // requestConfig.baseURL = '/';
      // requestConfig.url = url;
      // requestConfig.data = _data;
      // requestConfig.method = method;
      // requestConfig.withCredentials = true;

      return _data;
  }
}
